$(function () {
    $("#jqGrid").Grid({
        url: '../devplangcrecord/list',
        colModel: [
            {label: '规程名称', name: 'relDevPlan', index: 'REL_DEV_PLAN', width: 80},
            {label: '规程项名称', name: 'baseName', index: 'BASE_NAME', width: 80},
            //{label: '维护选项', name: 'baseId', index: 'BASE_ID', width: 80},
            {label: '设备名称', name: 'devName', index: 'devName', width: 80},
            {label: '实施频率', name: 'freRate', index: 'FRE_RATE', width: 80,formatter:function (v) {
                    return sysEnums.FRERATE[v];
                }},
            {label: '创建时间', name: 'createDate', index: 'CREATE_DATE', width: 80,formatter:function (v) {
                   return  transDate(v,'yyyy-MM-dd');
                }},
            {label: '方法手段', name: 'methodType', index: 'METHOD_TYPE', width: 80},
            {label: '执行状态', name: 'checkFlag', index: 'CHECK_FLAG', width: 80,formatter:function (v) {
                    return sysEnums.GC_CHECK[v];
                }},
            {label: '操作时间', name: 'authorDate', index: 'AUTHOR_DATE', width: 80},
            {label: '操作人', name: 'author', index: 'AUTHOR', width: 80},
            {label: '延期备注', name: 'remark', index: 'REMARK', width: 80},
            {label: 'id', name: 'id', index: 'ID', key: true, hidden: true},
        ]
    });
});

let vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        repairUserList:'',
        devPlanGcRecord: {
            delFlag: '',
            createDate: '',
            remark: '',
            checkFlag: '',
            authorDate: '',
            author: '',
            relDevPlan: '',
            id: '',
        },
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.devPlanGcRecord = {
                delFlag: '',
                createDate: '',
                remark: '',
                checkFlag: '',
                authorDate: '',
                author: '',
                relDevPlan: '',
                id: '',
            };
        },
        update: function (event) {
            let id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id);
        },
        saveOrUpdate: function (event) {
            let url = vm.devPlanGcRecord.id == (null || '') ? "../devplangcrecord/save" : "../devplangcrecord/update";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.devPlanGcRecord),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            let ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    url: "../devplangcrecord/delete",
                    params: JSON.stringify(ids),
                    type: "POST",
                    contentType: "application/json",
                    successCallback: function () {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../devplangcrecord/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.devPlanGcRecord = r.devPlanGcRecord;
                }
            });
        },
        reload: function (event) {
            vm.showList = true;
            let page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name},
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                name: ''
            };
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },
        assign:function () {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.getAssign();
            openWindow({
                title: "选择人员",
                area: ['500px', '300px'],
                content: jQuery("#select"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    //添加指派人,修改任务进度
                      vm.addMaintain();
                    layer.close(index);
                }
            });
        },
        getAssign: function () {
            //获取当前登录部门的维修组人员信息
            Ajax.request({
                url: '../devmaintenwork/repairUser',
                async: false,
                successCallback: function (r) {
                    vm.repairUserList = r.repairUserList;
                }
            })
        },
        addMaintain:function () {
            Ajax.request({
                url:'../',
                async:false,
                successCallback:function (r) {
                    
                }
            });
        }
    }
});
